package com.flyme.module.base.provider.service.impl;

import com.flyme.common.core.utils.ApiAssert;
import com.flyme.core.base.supper.service.impl.BaseServiceImpl;
import com.flyme.module.base.client.entity.SysVipconfig;
import com.flyme.module.base.provider.mapper.SysVipconfigMapper;
import com.flyme.module.base.provider.service.SysVipconfigService;
import com.flyme.module.exam.client.vo.ExamItem;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: zyf
 * @date: 2018/10/24 16:33
 * @description:
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SysVipconfigServiceImpl extends BaseServiceImpl<SysVipconfigMapper, SysVipconfig> implements SysVipconfigService {

    /**
     * 根据vip查询vip权限
     */
    public List<SysVipconfig> selectByVip(Long vipTypeId) {
        return list(q().eq("vipTypeId", vipTypeId).orderByAsc("sortOrder"));
    }

    @Override
    public Boolean deleteByVipTypeId(Long vipTypeId) {
        ApiAssert.notNull("vipTypeId", vipTypeId);
        return remove(q().eq(true, "vipTypeId", vipTypeId));
    }

    @Override
    public List<ExamItem> selectList(Long vipTypeId) {
        List<SysVipconfig> vipconfigList = list(q().eq("vipTypeId", vipTypeId));
        List<ExamItem> vipConfigItems = new ArrayList<>();
        int i = 1;
        for (SysVipconfig vipconfig : vipconfigList) {
            ExamItem examItem = new ExamItem();
            examItem.setValue(vipconfig.getVipPriItem());
            examItem.setIndex(i++);
            examItem.setStatus(1);
            vipConfigItems.add(examItem);
        }
        return vipConfigItems;
    }

}
